/**
 * 
 */
package it.easycrm.data.dao.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceException;
import javax.persistence.TypedQuery;

import org.springframework.orm.jpa.JpaCallback;

import it.easycrm.data.dao.interfaces.UserDao;
import it.easycrm.data.dataobjects.User;

/**
 * @author francesco
 *
 */
public class UserDaoImpl extends AbstractDaoJPAImpl<User> implements UserDao {

	public UserDaoImpl() {
		super(User.class);
	}
	public UserDaoImpl(Class<User> domainClass) {
		super(domainClass);
		
	}

	/* (non-Javadoc)
	 * @see it.easycrm.data.dao.interfaces.Dao#delete(it.easycrm.data.dataobjects.DomainObject)
	 */
	public void delete(User o) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see it.easycrm.data.dao.interfaces.Dao#save(it.easycrm.data.dataobjects.DomainObject)
	 */
	public User save(User o) {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see it.easycrm.data.dao.interfaces.Dao#findAll()
	 */
	public List<User> findAll() {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see it.easycrm.data.dao.interfaces.Dao#countAll()
	 */
	public int countAll() {
		// TODO Auto-generated method stub
		return 0;
	}
	public User getUserByUsername(final String username){
		
		return getJpaTemplate().execute(new JpaCallback<User>() {

			

			public User doInJpa(EntityManager em) throws PersistenceException {
				
				TypedQuery<User> query = em.createQuery("select u from User u  where u.username= :username ", User.class);
				query.setParameter("username", username);
				
				return query.getSingleResult();
			}
		});
		
	}

}
